<template>
  <!-- 我的收藏 -->
  <div class="box">
    <heads></heads>
    <titlesearch></titlesearch>
    <div class="gerenBox">
      <ceList :index="21"></ceList>
      <div class="con">
        <div class="one-tab no-padding">
          <div class="one-tab-left">
            <div
              class="one-tab-item "
              :class="leibie == 1 ? 'active' : ''"
              @click="leibieClick(1)"
            >
              我要反馈
            </div>
          </div>
          <div class="one-tab-right"></div>
        </div>
        <!-- <div class="leibie">
          <div class="anniu">
            <div :class="leibie == 1 ? 'xuan' : ''" @click="leibieClick(1)">
              
            </div>
          </div>
        </div> -->
        <div v-if="leibie == 1">
          <div class="report">
            <el-input
              class="textarea"
              type="textarea"
              v-model="wtfkText"
              maxlength="300"
              show-word-limit
              autosize
            ></el-input>
            <div class="tupian">
              <el-upload
                :action="$upLoad"
                list-type="picture-card"
                :limit="9"
                :accept="$imgSuffixArr.join(',')"
                :before-upload="beforeUpload"
                multiple
                :on-exceed="handleExceed"
                :on-success="houseSuccess"
                :on-remove="houseRemove"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
              <el-dialog :visible.sync="dialogVisible">
                <img
                  width="100%"
                  style="object-fit: contain;background-color: #00000033;"
                  :src="dialogImageUrl"
                  alt
                />
              </el-dialog>
            </div>
            <div class="problemFK" @click.stop="submitProblem">提交反馈</div>
          </div>
        </div>
        <div v-if="leibie == 2">
          <div class="report">
            <div class="selects">
              <el-select v-model="hfChage" @change="handleCommand">
                <el-option label="已回复" value="已回复"></el-option>
                <el-option label="已拒绝" value="已拒绝"></el-option>
                <el-option label="待审核" value="待审核"></el-option>
              </el-select>
            </div>

            <div
              class="report_item"
              v-for="(item, index) in collectList"
              :key="index"
            >
              <div>{{ item.feedback }}</div>
              <div class="report-img-wrap">
                <img
                  :src="eim"
                  v-for="(eim, index) in imgList"
                  :key="index"
                  class="report-img"
                  style="width: 100px;height: 100px;margin-right: 10px;"
                  @click.stop="preView(index, item)"
                />
              </div>
              <div class="time">{{ item.showTime }}</div>
            </div>

            <div v-if="collectList.length == 0" style="height: 450px">
              <el-empty :description="还没有反馈问题呢"></el-empty>
            </div>
          </div>
          <div class="fenye">
            <el-pagination
              background
              layout="prev, pager, next"
              :total="collectTotal"
              :current-page="collectPage.pageNo"
              :page-size="collectPage.pageSize"
              @current-change="CollectCurrentChange"
            ></el-pagination>
          </div>
        </div>
      </div>
    </div>
    <floor></floor>
    <chat ref="chats"></chat>
  </div>
</template>
<script>
import floor from "../../../components/floor";
import heads from "../../../components/head";
import ceList from "../../../components/ceList.vue";
import titlesearch from "../../../components/titlesearch.vue";
import chat from "../../../components/chat.vue";
export default {
  components: {
    floor,
    heads,
    ceList,
    titlesearch,
    chat
  },
  data() {
    return {
      imgList: [],
      leibie: 1,
      collectPage: {
        pageSize: 10,
        pageNo: 1,
        userId: "",
        replyStatus: 0, //回复状态（：全部，0：未回复，1：已回复）
        auditStatus: 2 //审核状态（0：待审核，1：已通过，2：已拒绝）
      },
      collectList: [],
      collectTotal: 0,
      houseImage: [],
      dialogImageUrl: "",
      dialogVisible: false,
      wtfkText: "",
      hfChage: ""
    };
  },
  created() {
    this.getUser();
    this.checkLogin(false, this.getMoreData);
    // @param replyStatus
    // @param auditStatus
    // replyStatus=
    // auditStatus
  },
  methods: {
    preView(index, item) {
      this.$hevueImgPreview({
        multiple: true,
        nowImgIndex: index,
        imgList: item.image
      });
    },
    leibieClick(num) {
      this.leibie = num;

      this.checkLogin(false, this.getMoreData);
    },
    CollectCurrentChange() {
      this.collectPage.pageNo = 1;
      this.getMoreData();
    },
    getMoreData() {
      if (this.leibie == 1) {
        // this.submitProblem();
      } else if (this.leibie == 2) {
        this.getAllFeedback();
        // this.getMyReportRecord();
      }
    },
    getAllFeedback() {
      this.$getHttp(
        "/api/mobile/public/getProblemFeedbackByReplyStatus",
        this.collectPage
      ).then(data => {
        if (data.code == 200) {
          this.collectList = data.page.list.map(item => {
            item.imgList = this.manageImg(item.image);
            item.showTime =
              this.createDate.split(" ")[0].split("-")[0] +
              "年" +
              this.createDate.split(" ")[0].split("-")[1] +
              "月" +
              this.createDate.split(" ")[0].split("-")[2] +
              "日";
          });
          this.collectTotal = data.page.count;
        }
      });
    },
    submitProblem() {
      if (!this.wtfkText || this.wtfkText == "") {
        this.$message({
          message: "请先输入文字！",
          type: "error",
          offset: 120,
          duration: 2000
        });
        return;
      }
      let data = {
        feedbackPerson: JSON.parse(localStorage.getItem("userInfo")).id,
        content: this.wtfkText,
        feedbackPicture: this.houseImage.map(item => item.path).join("|")
      };
      console.log(data);
      // return;
      if (this.loading) {
        return;
      }
      this.loading = true;
      this.$postHttp("/api/mobile/public/increaseProblemFeedback", data).then(
        res => {
          if (res.code == 200) {
            this.$message({
              message: "反馈成功！",
              type: "success",
              offset: 120,
              duration: 2000
            });
            // this.leibieClick(2)
          } else {
            this.loading = false;
          }
        }
      );
    },
    handleCommand() {},
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 9 个文件，本次选择了 ${
          files.length
        } 个文件，共选择了 ${files.length + this.houseImage.length} 个文件`
      );
    },
    houseSuccess(response, file, fileList) {
      this.houseImage.push({
        id: file.uid,
        path: response.data[0].url
      });
    },
    houseRemove(file, fileList) {
      for (var i = 0; i < this.houseImage.length; i++) {
        if (this.houseImage[i].id == file.uid) {
          this.houseImage.splice(i, 1);
        }
      }
    },
    beforeUpload(file, fileList) {
      if (file.size / (1024 * 1024) > 20) {
        // 限制文件大小
        this.$message.warning(`当前限制文件大小不能大于20M`);
        return false;
      }
      let suffix = file.name.substring(file.name.lastIndexOf(".") + 1); //获取文件后缀名
      let suffixArray = ["jpg", "png", "jpeg", "gif"]; //限制的文件类型，根据情况自己定义
      if (suffixArray.indexOf(suffix.toLowerCase()) === -1) {
        this.$message({
          message: "文件格式错误",
          type: "error",
          duration: 2000
        });
        return false;
      }
      return true;
    },
    getUser() {
      let user = JSON.parse(localStorage.getItem("userInfo"));
      if (user != null) {
        this.loginstate = true;
        this.collectPage.userId = user.id;
      } else {
        this.loginstate = false;
      }
    },
    checkLogin(slience = false, callback) {
      if (!this.loginstate) {
        if (!slience) {
          this.$message({
            message: "请先登录！",
            type: "error",
            offset: 120,
            duration: 2000
          });
        }
        return false;
      }
      callback && callback();
      return true;
    }
  }
};
</script>
<style lang="less" scoped>
.box {
  position: relative;
  padding-bottom: 200px;
}
.con {
  display: inline-block;
  box-sizing: border-box;
  vertical-align: top;
  width: 940px;
  color: #333;
  border: 1px solid #e0e0e0;
  .leibie {
    height: 80px;
    border-bottom: 1px solid #e0e0e0;
    padding-left: 40px;
    padding-right: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .anniu {
      div {
        display: inline-block;
        margin-right: 54px;
        font-size: 20px;
        cursor: pointer;
      }
      .xuan {
        transform: scale(1.2);
        color: #64b6a8;
      }
    }
  }
  .fenye {
    width: 100%;
    height: 50px;
    text-align: center;
    margin-bottom: 50px;
    margin-top: 50px;
  }
}
.gerenBox {
  width: 1200px;
  margin-left: 50%;
  transform: translateX(-50%);
  margin-top: 32px;
  margin-bottom: 45px;
  .geren {
    position: relative;
    display: inline-block;
    box-sizing: border-box;
    width: 240px;
    min-height: 820px;
    margin-right: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    overflow: hidden;
    img {
      width: 110px;
      height: 110px;
      border-radius: 50%;
      margin-top: 40px;
      margin-left: 65px;
    }
    p {
      width: 100%;
      text-align: center;
      font-size: 18px;
      color: #333333;
      margin-top: 12px;
      margin-bottom: 40px;
    }
    .list {
      position: relative;
      width: 100%;
      .li {
        width: 209px;
        height: 50px;
        line-height: 50px;
        margin-left: 30px;
        text-indent: 40px;
        font-size: 18px;
        color: #333;
        border-radius: 25px 0 0 25px;
        cursor: pointer;
      }
      .xuan {
        background-color: #64b6a8;
        color: #fff;
      }
    }
    .kuai {
      width: 100%;
      height: 6px;
      background-color: #64b6a8;
      position: absolute;
      bottom: 0;
    }
  }
}
.report {
  display: flex;
  flex-direction: column;
  .textarea {
    width: 865px;
    margin: 0 auto;
    margin-top: 25px;
    /deep/.el-textarea__inner {
      width: 865px;
      min-height: 130px !important;
      line-height: 25px;
      outline: none;
      padding: 10px 13px 30px 13px;
      overflow-y: visible;
    }
  }
  .selects {
    width: 130px;
    margin-top: 35px;
    margin-left: 35px;
  }
  .tupian {
    width: 865px;
    margin: 0 auto;
    margin-top: 25px;
  }
  .problemFK {
    cursor: pointer;
    width: 300px;
    height: 60px;
    background: #64b6a8;
    border-radius: 6px;
    font-size: 24px;
    font-weight: 400;
    color: #ffffff;
    margin: 0 auto;
    text-align: center;
    line-height: 60px;
    margin-top: 200px;
    margin-bottom: 100px;
  }
  .report_item {
    width: 100%;
    box-sizing: border-box;
    padding: 25px 35px;
    border-bottom: 10px solid #f2f2f2;
    .text {
      font-size: 18px;
      font-weight: 400;
      color: #333333;
    }
    .time {
      text-align: right;
      margin-top: 10px;
      font-size: 15px;
      font-weight: 400;
      color: #333333;
    }
  }
}
/deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #64b6a8 !important;
}
</style>
